package com.tanhua.api.mongo;

import com.tanhua.mongo.Visitors;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;
@Service
public class MovementsApiImpl implements MovementsApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<Visitors> visitors(Long userId, Long time) {
        Query query = new Query(Criteria.where("userId").is(userId).and("date").gt(time));
        List<Visitors> visitorsList = mongoTemplate.find(query, Visitors.class);
        return visitorsList;
    }

    @Override
    public void save(Visitors visitors) {
        mongoTemplate.save(visitors);
    }
}
